﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;

namespace BLL.StatSheme
{
     public  class B_AddScheme
     {
         OracleDAL.StatSheme.O_AddScheme oadd = new OracleDAL.StatSheme.O_AddScheme();
         /// <summary>
         /// 执行sql
         /// </summary>
         /// <param name="sql"></param>
         /// <returns>执行结果</returns>
         /// 
         #region 执行sql
         public int excuteSql(string sql)
         {
             return oadd.excuteSql(sql);

         }
         #endregion
       
         /// <summary>
         /// 得到选择的节点
         /// </summary>
         /// <param name="schemeId"></param>
         /// <returns>str</returns>
         /// 

         #region 得到选择的节点
         public string GetCheckNode(string schemeId)
         {
             DataSet ds = new DataSet();
             string checkNodeStr = "";

             string sql = "select nodeid  from com_statistics_scheme_node where id='" + schemeId + "'";

             ds = oadd.GetQuery(sql);
             if (ds.Tables[0].Rows.Count > 0)
             {
                 for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                 {
                     checkNodeStr += ds.Tables[0].Rows[i]["nodeid"].ToString() + ",";
                 }

             }
             return "," + checkNodeStr;
         }
#endregion
         public DataSet GetSchemeTitle(string id)
         {
             DataSet ds = new DataSet();
             string checkNodeStr = "";

             string sql = "select ID,USERISN,INDEXNEED,SCHEMENAME,ISPRIVATE  from com_statistics_scheme_title where ID='" + id + "'";

             ds = oadd.GetQuery(sql);
             return ds;
         }
         public DataSet getRepeat(string sql)
         {
             DataSet ds = new DataSet();
             ds = oadd.GetQuery(sql);
             return ds;
         }

         public DataSet GetTotalSchemeTitleByUser(string  useIsn)
         {
             DataSet ds = new DataSet();
             string checkNodeStr = "";

             string sql = "select ID,USERISN,INDEXNEED,SCHEMENAME,ISPRIVATE  from com_statistics_scheme_title where USERISN='" + useIsn + "'";

             ds = oadd.GetQuery(sql);
             return ds;
         }


         public void delNewResourceAndTitle(string schemeId)
         {
             string sql= " declare begin  delete com_statistics_sheme_operate where shemeid='" + schemeId + "';delete com_statistics_scheme_title where id='" + schemeId + "'; end;";
              oadd.excuteSql(sql);
         }


         public void delNewResourceAndNode(string schemeId)
         {
             string sql = " declare begin  delete com_statistics_scheme_node where id='" + schemeId + "';delete com_statistics_sheme_operate where shemeid='" + schemeId + "'; end;";
             oadd.excuteSql(sql);
         }
         public void delNode(string schemeId)
         {
             string sql = " declare begin  delete com_statistics_scheme_node where id='" + schemeId + "';end;";
             oadd.excuteSql(sql);
         }
         

         /// <summary>
         /// 删除方案  及其级联信息  回滚
         /// </summary>
         /// <param name="schemeId"></param>
         /// <returns></returns>
         /// 
         #region  删除方案  及其级联信息  回滚
         public int DelScheme(string schemeId)
         {
             string sql = " declare begin  delete com_statistics_scheme_node where id='" + schemeId + "';delete com_statistics_sheme_operate where shemeid='" + schemeId + "';delete com_statistics_scheme_title where id='" + schemeId + "'; end;";
             return oadd.excuteSql(sql);
         }
         #endregion
       
    }
}
